package com.llcbenwu.social;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.llcbenwu.config.Result;
import com.llcbenwu.util.ResultVOUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.view.AbstractView;
import org.w3c.dom.views.DocumentView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;


/**
 * @author lilinchun
 * @date 2021/11/9 0009 15:16
 */
public class ConnectionView extends AbstractView {

    @Autowired
    private ObjectMapper objectMapper;

    @Override
    protected void renderMergedOutputModel(Map<String, Object> map, HttpServletRequest request,
                                           HttpServletResponse response) throws Exception {
        response.setContentType("application/json;charset=UTF-8");
        //如果map（Model对象）里有Connection对象，则表示绑定，否则表示解绑
        if (map.get("connections") == null) {
            response.getWriter().write(objectMapper.writeValueAsString(ResultVOUtil.success("解绑成功")));
        } else {
            response.getWriter().write(objectMapper.writeValueAsString(ResultVOUtil.success("绑定成功")));
        }
    }

}
